package com.dup.jxlh.admin.aspect;

import com.dup.jxlh.admin.service.auth.AuthService;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

@Aspect
@Configuration
@Order(0)
public class UserPermissionUpdateAspect {
    @Autowired
    private AuthService authService;


    @Pointcut("execution(public * com.dup.jxlh.admin.controller..*(..))")
    public void pointCut() {
    }

    @Before("pointCut()")
    public void before() {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth.getDetails() != null && authService.checkCurrentAuthPermFlag(auth.getName())) {
            authService.resetCurrentAuthUserPerm(auth);
        }
    }
}